<?php
/**
* Base User class, help do things with users in the system.
*
* $Id: USER.class.php 37 2005-04-03 05:54:36Z vluther $ 				
* @package includes
* @version $Rev: 37 $
* @copyright Copyright &copy; 2000-2007, Linuxpowered, Inc               
* @author Vidyut Luther <vid@linuxpowered.com> 
**/

/**
 * The User Class
 *
 */
class User {

  /**
   * The User ID 
   *
   * @var int
   */
  var $userId; 
  
  /**
   * The username, (usually the email address)
   *
   * @var string
   */
  var $username ; 
  
  /**
   * User's firstname
   *
   * @var string
   */
  var $firstname; 
  
  /**
   * Users Lastname
   *
   * @var string
   */
  var $lastname ; 
  
  
  /**
   * The user level (role)
   *
   * @var int
   */
  var $userlevel ; 


  /**
   * The constructor. 
   *
   * @return User
   */
  function User()
  {
    $this->userId = null ; 
  }


  /**
   * Set the User Id 
   *
   * @param int $uid
   * @return boolean
   */
  function setUserId($uid)
  {
    $this->userId = $uid;
    return true; 
  }

	
/**
 * loadAll: Load All users into an Array 
 * 
 * @return 
 * @access 
 **/
  function loadAll()
  {
    if(is_null($userId)) {
      $sql = "SELECT userid,email,firstname,lastname FROM users "; 
      require_once(INCLUDE_PATH."/DB.php") ; 
      $db = new DB(); 
      $rs = $db->mRun($sql) ;
      while($row=mysql_fetch_assoc($rs)) {
        $arrUsers[] = $row;
      }
      return $arrUsers; 
    }

    return false; 


  }




  /**
   * Load all information on a  user based on a specific ID already set for previously by the setUser method.
   *
   * @access public 
   * @return array
   */
  function LoadUser()
  {

     if(!is_null($this->userId)) {
      $sql = "SELECT userid,email,firstname,lastname,password FROM users WHERE userid='$this->userId'"; 
      require_once(INCLUDE_PATH."/DB.php") ; 
      $db = new DB(); 
      $rs = $db->mRun($sql) ;
      while($row=mysql_fetch_assoc($rs)) {
        $arrUsers[] = $row;
        $this->username = $row['email']; 
        $this->password = $row['password']; 
      }
      return $arrUsers; 
    }

    return false; 

  }



  /**
   * Returns a list of users based on criteria. By default, it will return an entire list of users in the database. 
   *
   * access public
   * @param string $searchval
   * @return array
   */
  function UserList($searchval=null)
  {
    if(!is_null($searchval)) {
      $where = "WHERE userid='$searchval'"; 
    }

    $sql = "SELECT userid,email,firstname,lastname FROM users $where ORDER BY userid "; 
    require_once INCLUDE_PATH .'/DB.php'; 
    $db = new DB(); 
    $rs = $db->mRun($sql); 

    while($row=mysql_fetch_assoc($rs)) {
      $arrUsers[] = $row ; 
    }

    return $arrUsers; 




  }




}









?>
